﻿@{
    ViewBag.Title = "InterfaceDoc";
    Layout = "~/Views/Share/_Layout.cshtml";
}

@section css{
    <link href="/Content/noke/css/plugins/summernote/summernote.css" rel="stylesheet">
    <link href="/Content/noke/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
    <!-- Toastr style -->
    <link href="/Content/noke/css/plugins/toastr/toastr.min.css" rel="stylesheet">
}
@section head{
        
        <div class="col-sm-4">
            <ol class="breadcrumb">
                <li>
                    <a href="/">Home</a>
                </li>
                <li class="active">
                    <strong>接口文档</strong>
                </li>
            </ol>
        </div>

}

            <div class="row">
                <div class="col-lg-2">
                    <ul class="nav metismenu" id="doc-list">
                    </ul>
                </div>
                <div class="col-lg-10">
                    
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <div class="row">

                                <div class="col-sm-11">
                                    <h5>接口文档</h5>
                                </div>
                                <div class="col-sm-1">
                                    <div>
                                        <a href="javascript:edit(null);" class="btn btn-primary btn-sm">添加</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="panel-body">

                            <div class="tabs-container">
                                <ul class="nav nav-tabs">
                                    <li class="active"><a data-toggle="tab" href="#tab-1">基础信息</a></li>
                                    <li class=""><a data-toggle="tab" href="#tab-2">明细</a></li>
                                </ul>
                                <div class="tab-content">

                                    <div id="tab-1" class="tab-pane active">
                                        <div id="doc-modify" class="panel-body" style="display:none;"> 
                                            
                                            <div class="form-group">
                                                <button type="button" class="btn btn-primary" onclick="save();">Save</button>
                                            </div>

                                            <div class="form-group" style="display:none;">
                                                <label for="Id">ObjectId</label>
                                                <input id="Id" type="text" class="form-control" readonly="readonly" />
                                            </div>
                                            <div class="form-group">
                                                <label for="No">编号</label>
                                                <input id="No" type="text" class="form-control" readonly="readonly" />
                                            </div>
                                            <div class="form-group">
                                                <label for="IName">接口名称</label>
                                                <input id="IName" type="text" class="form-control" placeholder="接口名称 ..." />
                                            </div>
                                            <div class="form-group">
                                                <label for="URL">URL</label>
                                                <input id="URL" type="text" class="form-control" placeholder="接口名称 ..." />
                                            </div>
                                            <div class="form-group">
                                                <label for="Description">描述</label>
                                                <div class="Description wrapper p-md">
                                                    <h4 style="font-family: 'open sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 600; font-size: 16px;"><span style="line-height: 24px;">/// &lt;summary&gt;<br></span><span style="line-height: 24px;">/// <span style="color: rgb(231, 99, 99);">获取单个主商品对象<br></span></span><span style="line-height: 24px;">/// &lt;/summary&gt;<br></span><span style="line-height: 24px;">/// &lt;param name="<span style="background-color: rgb(255, 214, 99); color: rgb(57, 123, 33);">productBasicSysNo</span>"&gt;<span style="background-color: rgb(255, 214, 99); color: rgb(57, 123, 33);">主商品编号</span>&lt;/param&gt;<br></span><span style="line-height: 24px;">/// &lt;returns&gt;<span style="color: rgb(57, 123, 33); background-color: rgb(255, 214, 99);">主商品实例</span>&lt;/returns&gt;<br></span><span style="line-height: 24px; color: rgb(107, 165, 74);">ProductBasicModel GetProductBasic(int m_ProductBasicSysNo);</span></h4><ul></ul>
                                                </div>
                                            </div>                                        
                                            <button type="button" class="btn btn-primary" onclick="save();">Save</button>
                                            
                                        </div>

                                        <div id="doc-show" class="panel-body" style="display:none;">
                                            
                                            <div class="ibox-content profile-content">
                                                <h4><strong id="i-name"></strong></h4>
                                                <p><i class="fa fa-map-marker"></i> <span  id="i-id-no"></span></p>
                                                <h5>
                                                    Service Interface URL:
                                                </h5>
                                                <p id="i-url"></p>
                                                <button type="button" class="btn btn-primary btn-sm" onclick="modify();"><i class="fa fa-pencil"></i> Edit </button>
                                                <div class="user-button">
                                                    <div class="row">
                                                        <div class="col-md-6">
                                                        </div>
                                                        <div class="col-md-6">
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div id="tab-2" class="tab-pane">
                                        <div id="i-detail" class="panel-body"></div>
                                    </div>

                                </div>


                            </div>




                        </div>

                    </div>

                </div>

            </div>

@section scripts{
    
    <!-- SUMMERNOTE -->
    <script src="/Content/noke/js/plugins/summernote/summernote.min.js"></script>
    
    <!-- Toastr script -->
    <script src="/Content/noke/js/plugins/toastr/toastr.min.js"></script>

    <script>
        $(document).ready(function () {

            get(0);

            $('.Description').summernote();

        });


        function get(no, thisno, ismodify) {            
            var url = '';

            if (no) {
                url = '/Doc/GetInterfaceDoc/' + no;
                $.getJSON(url, function (res) {
                    if (res.Code == 100 && res.Value) {
                        if (ismodify)
                            edit(res.Value);
                        else {
                            show(res.Value);
                        }
                    } else {
                        console.log('Get:' + res.Msg);
                    }
                }, 'json');
                return false;
            }

            url = '/Doc/GetInterfaceDocList/';
            $.getJSON(url, function (res) {
                if (res.Code == 100 && res.Value && res.Value.length > 0) {
                    var sHtml = '', model = null;
                    $(res.Value).each(function (i, item) {
                        if (i == 0) { model = item; }
                        if (thisno && item.No == thisno) { model = item; }
                        sHtml += '<li class="special_link"> <a href="javascript:get(' + item.No + ');"> <i class="fa fa-file"></i> <span class="nav-label">' + item.IName + '</span> </a></li>';
                    });
                    $('#doc-list').html(sHtml);
                    show(model);
                } else {
                    console.log('Get List:' + res.Msg);
                }
            }, 'json');

        };
        
        var edit = function (model) {
            if (model) {
                $('#Id').val(model.Id);
                $('#No').val(model.No);
                $('#IName').val(model.IName);
                $('.Description').code(decodeURIComponent(model.Description));
                $('#URL').val(model.URL);
                $('#i-detail').html(decodeURIComponent(model.Description));
            } else {
                $('#Id').val('');
                $('#No').val((new Date()).valueOf());
                $('#IName').val('');
                $('.Description').code('这里编写服务接口文档...');
                $('#URL').val('');
                $('#i-detail').html('');
            }
            $('#doc-show').hide();
            $('#doc-modify').show();
        }

        var modify = function () {
            var no = $('#No').val();
            get(no, no, true);
        }

        var save = function () {
            var model = { No: $('#No').val(), IName: $('#IName').val(), Description: '', URL: $('#URL').val() };
            model.Description = encodeURIComponent($.trim($('.Description').code()));

            var url = '/Doc/SaveInterfaceDoc/';

            $.post(url, model, function (res) {
                if (res.Code == 100) {
                    get(null, model.No);
                } else {
                    console.log('Save: ' + res.Msg);
                }
            }, 'json');
            
        };

        var show = function (model) {
            if (!model)
                return false;
            $('#No').val(model.No);
            $('#i-name').html(model.IName);
            $('#i-id-no').html(model.Id + '-' + model.No);
            $('#i-url').html(model.URL);
            $('#i-detail').html(decodeURIComponent(model.Description));

            $('#doc-modify').hide();
            $('#doc-show').show();
        }

    </script>

}